{include file='public/meta'}
<title>广告管理 - 插件管理 - 木鱼内容管理系统</title>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
		    		<div style="padding: 10px; background-color: #FAFAFA;">
              <div class="layui-row layui-col-space15">
                <div class="layui-col-md13">
                <div class="layui-card">
                    <div class="layui-card-header muyu-text">操作台&nbsp; &nbsp; &nbsp;<span class="muyu-tips-right">Tips:如果未设置自动过期,需要手动隐藏!</span></div>
                    <div class="layui-card-body" style="display:inline-block;">
                    <span style="display:inline-block;">选中项：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
					  <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="delAll()" href="javascript:;">批量删除</a>
					  <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-normal" onclick="status()" href="javascript:;">批量隐藏</a>
					</div>
                    </div>
                    <div class="layui-card-body" style="display:inline-block;">
                    <span style="display:inline-block;">其他操作：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
					  <a class="layui-btn layui-btn-xs" onclick="openwind('添加广告','{:url('admin/Plug/addcreate')}')" href="javascript:;">添加广告</a>
					</div>
                    </div>
                    </div>
                </div>
                </div>  
            </div>
		    <div style="padding: 10px 15px 20px 15px;">
            <span style="float:left;">共有广告：<span style="color:red;">{$list|count}</span> 条</span>
			</div>
			<div class="layui-card-body">
            <div class="layui-table-body layui-table-main">
                <table class="layui-table" id="LAY-user-front-submit">
					<thead>
						<tr>
						    <th class=" layui-table-col-special">
							    <div class="layui-table-cell laytable-cell-checkbox">
							        <input type="checkbox" id="checkAll" onclick="isCheck()">
							    </div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>id</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>广告名称</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>广告跳转URL</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>广告展示图</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>广告文字型</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>到期时间</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>状态</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>操作</span></div>
							</th>
						</tr>
					</thead>
					<tbody>
					    {foreach $list as $val}
						<tr align="center">
						    <td class="layui-table-col-special">
								<input type="checkbox" name="fav" value="{$val.id}">
							</td>
							<td>{$val.id}</td>
							<td><span style="{eq name='$val.status' value='0'}color:red;{/eq}"></span>{$val.title}</td>
							<td>{$val.url}</td>
							<td>{gt name="$val['adphoto']" value="0"}
							    <img width="100px" height="60px" class="layui-upload-img" src="{$val.adphoto}">
							    {else/}无图
							    {/gt}
							</td>
							<td>{$val.adtext}</td>
							<td>{$val.outtime|date='Y-m-d'}</td>
							<td><div class="layui-table-cell">
                                      <a class="layui-btn-xs layui-btn layui-btn-{php}echo $val['status'] == '显示' ? 'btn' : 'danger';{/php}">{$val.status}</a>
                                </div>
                            </td>
							<td align="center"  class="layui-table-col-special">
								<div class="layui-table-cell">
								    <a class="layui-btn layui-btn-xs layui-btn-normal" onclick="addstatus('{$val.id}')" href="javascript:;"><i class="layui-icon layui-icon-face-{php}echo $val['status'] == '显示' ? 'cry' : 'smile';{/php}"></i>{php}echo $val['status'] == '显示' ? '隐藏' : '显示';{/php}</a>
								    <a class="layui-btn layui-btn-xs" onclick="openwind('广告编辑','{:url('admin/Plug/addedit',['id'=>$val.id])}')" href="javascript:;">编辑</a>
								    <a class="layui-btn layui-btn-xs layui-btn-warm" onclick="delAll('{$val.id}')" href="javascript:;">删除</a>
								</div>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
            </div>
            <div class="layui-box layui-laypage layui-laypage-molv">{$list|raw}</div>
		</div>

	</div>


	<!-- 低部区域 -->
	{include file='public/footer'}
	<script>
	layui.config({
    base: '__ADMINST__layuiadmin/' //静态资源所在路径
	,version: new Date().getTime()
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'upload'], function(){
    var $ = layui.$
    ,form = layui.form ;
  })
  
	 // 全选 页面调用
    function isCheck(){
        var IsCheck= document.getElementById("checkAll");
        if(IsCheck.checked==false){
            var groupC= document.getElementsByName("fav");
            for(var i=0;i<groupC.length;i++){
                groupC[i].checked=false;
            }
        }
        if (IsCheck.checked==true) {
            var groupC= document.getElementsByName("fav");
            for(var i=0;i<groupC.length;i++){
                groupC[i].checked=true;
            }
        }
    }
    //删除操作/批量删除    
    function delAll(id){
	var aid=$("tbody input:checkbox");
	var ids=[];
	//不给参数id时获取全选选中的id
	if(id == null){
		for(i=0;i<aid.length;i++){
			if($(aid[i]).is(":checked")){
				ids+=$(aid[i]).val()+',';
				id = ids;
			}
		}
	}
	console.log(id);
	if(id != "" && id != null){
		layer.msg('确认删除？',{
			time:5000,
			shade:0.3,
			btn:['确认','取消'],
			yes: function(){
				//执行删除
				$.post("{:url('admin/Plug/adddelete')}",{delid:id},function(data){
					if(data.code === 1){
						layer.msg(data.msg,{time:2000},function(){
							if(data.url) location.href = data.url;
						});
					}else{
						layer.msg(data.msg,{time:2000});
					}
				})
			}
		});
	}else{
		layer.msg("当前未选择任何信息！",{icon:2,time:2000});
	   }
	}
    
    //状态变更
    function addstatus(id){
        layer.msg('确认要变更状态吗？', {
		time: 5000, //5s后自动关闭
		shade: 0.3,
		btn: ['确认', '取消'],
		yes: function() {
			//执行变更
			$.post("{:url('admin/Plug/addstatus')}",{id:id}, function(data) {
			    if(data.code === 1){
			        layer.msg(data.msg, {time: 2000}, function() {
					location.reload();
				    });
			    }else{
			        layer.msg(data.msg, {time: 2000});
			    }
			})
		   }
		});
	}  

	


	</script>
</body>
</html>